/**
 * Utility for managing object URLs to prevent memory leaks
 */
class ObjectUrlManager {
  private urls: Set<string> = new Set();
  
  /**
   * Create an object URL and track it
   * @param blob Blob or File to create URL for
   * @returns Object URL
   */
  create(blob: Blob | File): string {
    const url = URL.createObjectURL(blob);
    this.urls.add(url);
    return url;
  }
  
  /**
   * Revoke an object URL and remove it from tracking
   * @param url URL to revoke
   */
  revoke(url: string): void {
    if (this.urls.has(url)) {
      URL.revokeObjectURL(url);
      this.urls.delete(url);
    }
  }
  
  /**
   * Revoke all tracked object URLs
   */
  revokeAll(): void {
    this.urls.forEach(url => {
      URL.revokeObjectURL(url);
    });
    this.urls.clear();
  }
}

export default new ObjectUrlManager();